<template>
	<view class="content">
		<image class="image" :src="path"></image>
		<kps-image-cutter @ok="onok" @cancel="oncancle" :url="url" :fixed="true" :blob="false" :width="690"
			:height="400">
		</kps-image-cutter>
	</view>
</template>

<script>
	import kpsImageCutter from "@/components/ksp-image-cutter/ksp-image-cutter.vue";
	export default {
		components: {
			kpsImageCutter
		},
		data() {
			return {
				Uplink: '',
				url: ''
			}
		},
		onLoad(opitst) {
			console.log(opitst, "11111")
			let that = this;
			//获取图片的本地图片
			uni.getImageInfo({
				src: opitst.coverImg,
				success: function(image) {
					console.log(image, "11111111")
					that.url = image.path
				}
			});

			this.Uplink = getApp().globalData.upHttp
		},
		methods: {
			// 确定裁剪
			onok(ev) {
				uni.showLoading({
					title: "裁剪中..."
				})
				let that = this
				uni.uploadFile({
					url: that.Uplink + 'admin/upload-img',
					filePath: ev.path,
					name: 'imgFile',
					header: {
						'Authorization': uni.getStorageSync('token')
					},
					success(res) {
						let data = JSON.parse(res.data)

						if (data.code === 0) {
							uni.hideLoading()
							// 改变上一个页面的data值
							var pages = getCurrentPages();
							var page = pages[pages.length - 2];
							page.$vm.bannerImg = data.data.imgUrl
							uni.navigateBack({
								delta: 1
							})
						} else {
							uni.showToast({
								title: "图片格式错误"
							})
						}
					}
				})
			},
			// 取消返回
			oncancle() {
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style>
	.image {
		width: 200px;
		height: 200px;
	}
</style>
